﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AcessoDados;
using System.Data.Linq;
using System.Web.Security;
namespace Loja
{
    public partial class MasterPage : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                rptMenu.DataSource = new AcessoDados.TipoProdutoDAO().Select();
                rptMenu.DataBind();

                if (Request.Cookies["cliente"] != null && Request.Cookies["cliente"].Values.Count > 1)
                {
                    using (LojaChocolateDCDataContext dc = new LojaChocolateDCDataContext())
                    {
                        short clicod = short.Parse(Request.Cookies["cliente"].Values["codigo"]);
                        Table<Cliente> tblCliente = dc.GetTable<Cliente>();
                        Cliente cliente = tblCliente.Where(c => c.CliID == clicod).SingleOrDefault();
                        Session["Cliente"] = cliente;
                    }
                }
            }
            if (Session["Cliente"] != null)
            {
                btnSair.Visible = true;
                btnMyData.Visible = true;
            }
            else
            {
                btnSair.Visible = false;
                btnMyData.Visible = false;
            }
        }

        protected void Sair_Click(object sender, EventArgs e)
        {
            Session["Cliente"] = null;
            //HttpContext.Current = null;
            FormsAuthentication.SignOut();
            Response.Redirect(Page.ResolveUrl("~/store/Home.aspx"));
        }

        protected void MyData_Click(object sender, EventArgs e)
        {
             Response.Redirect(Page.ResolveUrl("~/customer/") + "ListaPedidos.aspx");
        }

        protected void btnCadastro_Click(object sender, EventArgs e)
        {
            Response.Redirect(Page.ResolveUrl("~/customer/") + "ListaPedidos.aspx");
        }
    }
}